﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Anchor.Miscellaneous
{
    public class Bootup
    {
        public static Dictionary<int, string> PacketTypes = new Dictionary<int, string>(); 
        public static List<UserPackets> Packets = new List<UserPackets>();

        public void Boot()
        {
            //Boot up types
            this.BootTypes();

            //Boot up packets
            this.BootPackets();
        }
        public UserPackets getPacket(int id)
        {
            foreach (UserPackets packet in Packets)
            {
                if (packet.mRecId == id)
                {
                    return packet;
                }
            }
            return null;
        }
        private void BootTypes()
        {
            using (DatabaseClient dbClient = Environment.GetDatabase().GetClient())
            {
                DataTable Table = dbClient.ReadDataTable("SELECT * FROM packet_types;");

                foreach (DataRow row in Table.Rows)
                {
                    PacketTypes.Add((int)row["id"], (string)row["key"]);

                }
            }
        }
        private void BootPackets()
        {
            using (DatabaseClient dbClient = Environment.GetDatabase().GetClient())
            {
                DataTable Table = dbClient.ReadDataTable("SELECT * FROM packet_connection;");

                foreach (DataRow row in Table.Rows)
                {
                    Packets.Add(new UserPackets((int)row["requestid"], (int)row["sentid"], (int)row["typeid"], (string)row["content"]));

                }
            }
        }
    }
}
